home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-09-23 | 10.6 KB | 442 lines | [TEXT/MPS ] |
- // UEenie.cp --------------------------------------------------------------------------
- // Copyright © 1991 by Apple Computer, Inc. All rights reserved.
-
- #pragma once
-
- // INCLUDES ---------------------------------------------------------------------------
-
- #include "EenieRez.h" // combined header file for resource IDs
- #include "UEenie.h" // class definitions
-
-
- // CLASS METHODS ----------------------------------------------------------------------
-
- // TAdornerApplication ----------------------------------------------------------------
-
- #pragma segment AInit
- pascal void TAdornerApplication::IAdornerApplication(OSType fileType, OSType creator)
- {
- inherited::IApplication(fileType, creator);
-
- if (gDeadStripSuppression){ // so the linker doesn't dead strip class info
- macroDontDeadStrip(TEenieView1);
- macroDontDeadStrip(TEenieView2);
- macroDontDeadStrip(TEenieView3);
- macroDontDeadStrip(TEenieView4);
- macroDontDeadStrip(TGrayFill);
- macroDontDeadStrip(TOtherGrayFill);
- macroDontDeadStrip(TEtchedFrame);
- }
- RegisterStdType("TGrayFill", 'gray'); // register adorner types
- RegisterStdType("TOtherGrayFill", 'dgry');
- RegisterStdType("TEtchedFrame", 'etch');
- }
-
-
- #pragma segment AOpen
- pascal TDocument* TAdornerApplication::DoMakeDocument(CommandNumber /* itsCmdNumber */,
- TFile* /* itsFile */)
- {
- FailInfo fi;
-
- if(fi.Try()){
- TAdornerDocument* aAdornerDocument = new TAdornerDocument;
- aAdornerDocument->IAdornerDocument();
- return aAdornerDocument;
- fi.Success();
- }
- else
- fi.ReSignal();
- }
-
-
- // TAdornerDocument Methods -----------------------------------------------------------
-
- #pragma segment AInit
- pascal void TAdornerDocument::IAdornerDocument()
- {
- inherited::IDocument();
- }
-
-
- #pragma segment AOpen
- pascal void TAdornerDocument::DoMakeViews(Boolean /*forPrinting*/)
- {
- TWindow* aWindow = NULL;
- TEenieView1* view1 = NULL;
- TEenieView2* view2 = NULL;
- TEenieView3* view3 = NULL;
- TEenieView4* view4 = NULL;
-
- FailInfo fi;
-
- if(fi.Try()){
- // create Window
- aWindow = (TWindow *)gViewServer->NewTemplateWindow(kDefaultWindowID, this);
-
- // add window adorner
- aWindow->AddAdorner(NewStdAdorner('dgry',"",'dgry', kFreeOnDeletion),
- kAdornLast, kRedraw);
-
- // create views
- view1 =(TEenieView1 *) aWindow->FindSubView('VW01'); FailNIL(view1);
- view2 =(TEenieView2 *) aWindow->FindSubView('VW02'); FailNIL(view2);
- view3 =(TEenieView3 *) aWindow->FindSubView('VW03'); FailNIL(view3);
- view4 =(TEenieView4 *) aWindow->FindSubView('VW04'); FailNIL(view4);
-
- // add adorners to the new views
- view1->AddAdorner(NewStdAdorner('gray',"",'gray', kFreeOnDeletion),
- kAdornFirst, kRedraw);
- view2->AddAdorner(NewStdAdorner('gray',"",'gray', kFreeOnDeletion),
- kAdornFirst, kRedraw);
- view3->AddAdorner(NewStdAdorner('gray',"",'gray', kFreeOnDeletion),
- kAdornFirst, kRedraw);
- view4->AddAdorner(NewStdAdorner('gray',"",'gray', kFreeOnDeletion),
- kAdornFirst, kRedraw);
-
- // create dependencies
- view1->AddDependent(view4); view2->AddDependent(view3);
- view3->AddDependent(view2); view4->AddDependent(view1);
-
- fi.Success();
- }
- else
- fi.ReSignal();
- }
-
-
- // TEenieView ----------------------------------------------------------------
-
- #pragma segment AInit
- pascal void TEenieView::Initialize()
- {
- inherited::Initialize();
- }
-
-
- #pragma segment ARes
- pascal void TEenieView::DoPostCreate(TDocument* itsDocument)
- {
- inherited::DoPostCreate(itsDocument);
- this->fCounter = 0L; // zero counter
- this->AddAdorner(NewStdAdorner('etch',"",'etch', kFreeOnDeletion),
- kAdornFirst, kRedraw);
- }
-
-
- #pragma segment Main
- pascal void TEenieView::Hilite()
- {
- Rect tempRect;
-
- this->GetQDExtent(tempRect); // get the area
- BitClr((Ptr)HiliteMode, 0); // clear bit for selection color
- HiliteColor(gDKPink); // switch temp to new hilite color
- InvertRect(tempRect); // invert the area
- }
-
-
- // TEenieView SubViews ----------------------------------------------------------
-
- #pragma segment ARes
- pascal void TEenieView1::Draw(const VRect& area)
- {
- inherited::Draw(area);
- this->DrawNumber();
- }
-
-
- #pragma segment ARes
- pascal void TEenieView1::DrawNumber()
- {
- Str255 first = "Moo view clicked";
- Str255 count;
- Str255 second = "times...";
-
- PenNormal();
-
- TextFont(times); TextSize(14); MoveTo(10,15);
- DrawString(first);
-
- TextSize(48); MoveTo(40,90);
- NumToString(this->fCounter, count);
- DrawString(count);
-
- TextSize(14); MoveTo(10,140);
- DrawString(second);
- }
-
- #pragma segment Main
- pascal void TEenieView1::DoMouseCommand(VPoint& /*theMouse*/,
- TToolboxEvent* /*event*/,
- Point /*hysteresis*/)
- {
- this->Hilite(); // flash for the user for mouse click
- this->Changed(eVIEW1,this); // send change directive to dependent view
- }
-
- #pragma segment ARes
- pascal void TEenieView1::DoUpdate( ChangeID theID,
- TObject* /*changedObject*/,
- TObject* /*changedBy*/)
- {
- if (theID == eVIEW4){
- this->fCounter = this->fCounter + 1L; // increment counter
- this->ForceRedraw(); // update the screen
- }
- }
-
-
- // --------------------------
-
- #pragma segment ARes
- pascal void TEenieView2::Draw(const VRect& area)
- {
- inherited::Draw(area);
- this->DrawNumber();
- }
-
-
- #pragma segment ARes
- pascal void TEenieView2::DrawNumber()
- {
- Str255 first = "Minee view clicked";
- Str255 count;
- Str255 second = "times...";
-
- PenNormal();
-
- TextFont(times); TextSize(14); MoveTo(10,15);
- DrawString(first);
-
- TextSize(48); MoveTo(40,90);
- NumToString(this->fCounter, count);
- DrawString(count);
-
- TextSize(14); MoveTo(10,140);
- DrawString(second);
- }
-
-
- #pragma segment Main
- pascal void TEenieView2::DoMouseCommand(VPoint& /*theMouse*/,
- TToolboxEvent* /*event*/,
- Point /*hysteresis*/)
- {
- this->Hilite(); // flash for the user for mouse click
- this->Changed(eVIEW2,this); // send change directive to dependent view
- }
-
-
- #pragma segment ARes
- pascal void TEenieView2::DoUpdate( ChangeID theID,
- TObject* /*changedObject*/,
- TObject* /*changedBy*/)
- {
- if (theID == eVIEW3) {
- this->fCounter = this->fCounter + 1L; // increment counter
- this->ForceRedraw(); // update the screen
- }
- }
-
-
- // --------------------------
-
- #pragma segment ARes
- pascal void TEenieView3::Draw(const VRect& area)
- {
- inherited::Draw(area);
- this->DrawNumber();
- }
-
-
- #pragma segment ARes
- pascal void TEenieView3::DrawNumber()
- {
- Str255 first = "Meenie view clicked";
- Str255 count;
- Str255 second = "times...";
-
- PenNormal();
-
- TextFont(times); TextSize(14); MoveTo(10,15);
- DrawString(first);
-
- TextSize(48); MoveTo(40,90);
- NumToString(this->fCounter, count);
- DrawString(count);
-
- TextSize(14); MoveTo(10,140);
- DrawString(second);
- }
-
-
- #pragma segment Main
- pascal void TEenieView3::DoMouseCommand(VPoint& /*theMouse*/,
- TToolboxEvent* /*event*/,
- Point /*hysteresis*/)
- {
- this->Hilite(); // flash for the user for mouse click
- this->Changed(eVIEW3,this); // send change directive to dependent view
- }
-
-
- #pragma segment ARes
- pascal void TEenieView3::DoUpdate( ChangeID theID,
- TObject* /*changedObject*/,
- TObject* /*changedBy*/)
- {
- if (theID == eVIEW2) {
- this->fCounter = this->fCounter + 1L; // increment counter
- this->ForceRedraw(); // update the screen
- }
- }
-
-
- // --------------------------
-
- #pragma segment ARes
- pascal void TEenieView4::Draw(const VRect& area)
- {
- inherited::Draw(area);
- this->DrawNumber();
- }
-
- #pragma segment ARes
- pascal void TEenieView4::DrawNumber() // draw information in view
- {
- Str255 first = "Eenie view clicked";
- Str255 count;
- Str255 second = "times...";
-
- PenNormal();
-
- TextFont(times); TextSize(14); MoveTo(10,15);
- DrawString(first);
-
- TextSize(48); MoveTo(40,90);
- NumToString(this->fCounter, count);
- DrawString(count);
-
- TextSize(14); MoveTo(10,140);
- DrawString(second);
- }
-
-
- #pragma segment Main
- pascal void TEenieView4::DoMouseCommand(VPoint& /*theMouse*/,
- TToolboxEvent* /*event*/,
- Point /*hysteresis*/)
- {
- this->Hilite(); // flash for the user for mouse click
- this->Changed(eVIEW4,this); // send change directive to dependent view
- }
-
- #pragma segment ARes
- pascal void TEenieView4::DoUpdate( ChangeID theID,
- TObject* /*changedObject*/,
- TObject* /*changedBy*/)
- {
- if (theID == eVIEW1){
- this->fCounter = this->fCounter + 1L; // increment counter
- this->ForceRedraw(); // update the screen
- }
- }
-
-
- // TAdorners ------------------------------------------------------------------
-
- #pragma segment ARes
- pascal void TGrayFill::Draw(TView* itsView, const VRect& /*area*/)
- {
- RGBColor saveColor;
- PenState savePenState;
- VRect adornArea;
- Rect QDArea;
- Rect tempRect;
-
- GetPenState(savePenState); // save off the current pen state
- GetIfColor(saveColor); // and the foreground color
- PenNormal();
-
- itsView->GetAdornExtent(adornArea); // get area
- itsView->ViewToQDRect(adornArea, QDArea);
- tempRect = QDArea;
-
- SetIfColor(gRGBGray); // colorize it
- PaintRect(tempRect);
-
- SetIfColor(saveColor); // restore the foreground color and the pen
- SetPenState(savePenState);
- }
-
-
- #pragma segment ARes
- pascal void TOtherGrayFill::Draw(TView* itsView, const VRect& /*area*/)
- {
- RGBColor saveColor;
- PenState savePenState;
- VRect adornArea;
- Rect QDArea;
- Rect tempRect;
-
- GetPenState(savePenState); // save off the current pen state
- GetIfColor(saveColor); // and the foreground color
- PenNormal();
-
- itsView->GetAdornExtent(adornArea); // get area
- itsView->ViewToQDRect(adornArea, QDArea);
- tempRect = QDArea;
-
- SetIfColor(gDKGray); // dark gray scale, grey for you English
- PaintRect(tempRect);
-
- SetIfColor(saveColor); // Restore the foreground color and the pen
- SetPenState(savePenState);
- }
-
-
- #pragma segment ARes
- pascal void TEtchedFrame::Initialize()
- {
- inherited::Initialize();
- fInset.h = 1;
- fInset.v = 1;
- }
-
-
- #pragma segment ARes
- pascal void TEtchedFrame::Draw(TView* itsView, const VRect& /*area*/)
- {
- RGBColor saveColor;
- PenState savePenState;
- VRect adornArea;
- Rect QDArea;
- Rect tempRect;
-
- GetPenState(savePenState); // Save off the current pen state
- GetIfColor(saveColor); // and the foreground color
- PenNormal();
-
- itsView->GetAdornExtent(adornArea); // get area
- itsView->ViewToQDRect(adornArea, QDArea);
- tempRect = QDArea;
-
- SetIfColor(gRGBBlack);
- InsetRect(tempRect, fInset.h, fInset.v);
- FrameRect(tempRect); // Frame the shadows
-
- OffsetRect(tempRect, 1, 1);
- SetIfColor(gRGBWhite);
- FrameRect(tempRect); // Frame the light edges
-
- OffsetRect(tempRect, -1, -1);
- SetCPixel(tempRect.left, tempRect.bottom, gRGBBlack); // Finish the corners
- SetCPixel(tempRect.right, tempRect.top, gRGBBlack);
-
- SetIfColor(saveColor); // Restore the foreground color and the pen
- SetPenState(savePenState);
- }
-
-
-